package com.javakc.pms.dispord.service;

import com.javakc.commonutils.jpa.base.service.BaseService;
import com.javakc.commonutils.jpa.dynamic.SimpleSpecification;
import com.javakc.commonutils.jpa.dynamic.SimpleSpecificationBuilder;
import com.javakc.pms.dispord.dao.DispOrdDao;
import com.javakc.pms.dispord.entity.DispOrd;
import com.javakc.pms.dispord.vo.DispOrdQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * 描述：
 */
@Service
public class DispOrdService extends BaseService<DispOrdDao,DispOrd> {

    @Autowired
    private DispOrdDao dispOrdDao;

    public List<DispOrd> findAllDispord(){
        return dispOrdDao.findAll();
    }

    public Page<DispOrd> queryByPage(Integer pageNo, Integer pageSize, DispOrdQuery dispOrdQuery){
        // 设置条件
        SimpleSpecificationBuilder ssb=new SimpleSpecificationBuilder();
        if (!ObjectUtils.isEmpty(dispOrdQuery.getOrderName())){
            ssb.and("orderName",":",dispOrdQuery.getOrderName());
        }
        return dao.findAll(ssb.getSpecification(),PageRequest.of(pageNo-1,pageSize));
    }
}
